package com.matt.foundation.query;

import com.matt.commons.exception.BusinessException;

import com.matt.commons.model.ErrorCode;
import com.matt.commons.page.PagerQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/12/21
 * *******************************
 */

@Data
@EqualsAndHashCode(callSuper = true)
public class EvaluateQuery extends PagerQuery {

    @ApiModelProperty("宝宝id")
    private String childrenId;

    @ApiModelProperty("员工id")
    private String staffId;

    @ApiModelProperty(hidden = true)
    private String areaId;

    @ApiModelProperty("宝宝名称")
    private String childrenName;

    @ApiModelProperty("班级名称")
    private String className;

    private Integer month;

    private Integer orderStatus;

    private Integer status;

    private String orderBy;

    private String sequence;

    private List<String> createTimeQuery;

    public void validateOrderByAndSequence(){

        if( (StringUtils.isNotBlank(getOrderBy())
                && !"created".equalsIgnoreCase(getOrderBy())
                && !"status".equalsIgnoreCase(getOrderBy())
                && !"month".equalsIgnoreCase(getOrderBy())
                && !"weight".equalsIgnoreCase(getOrderBy())
                && !"height".equalsIgnoreCase(getOrderBy())
                && !"header".equalsIgnoreCase(getOrderBy())
                && !"published".equalsIgnoreCase(getOrderBy())
                && !"birthday".equalsIgnoreCase(getOrderBy())
        )
                || (StringUtils.isNotBlank(getSequence()) && !"desc".equalsIgnoreCase(getSequence()) && !"asc".equalsIgnoreCase(getSequence())) ){
            throw new BusinessException(ErrorCode.UNDEFINED, "参数错误");
        }

    }

}
